package org.example.schdule;

import org.example.pojo.domain.OperationalMonitoring;
import org.example.service.ExhibitionService;
import org.example.service.OperationalMonitoringService;
import org.example.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;

@Component
public class OperationalDataCollectorTask {

    @Autowired
    private OperationalMonitoringService operationalMonitoringService;

    @Autowired
    private ReservationService reservationService;

    @Autowired
    private ExhibitionService exhibitionService;

    @Scheduled(cron = "0 0 0 * * ?") // 每天午夜执行
    public void collectOperationalData() {
        int visitorsCount = reservationService.getVisitorsCount(); // 获取当天参观人数
        int eventCount = exhibitionService.getEventCount(); // 获取当天活动数量

        // 创建监控数据对象
        OperationalMonitoring monitoringData = new OperationalMonitoring();
        monitoringData.setDate(new Date());
        monitoringData.setVisitorsCount(visitorsCount);
        monitoringData.setExhibitionRevenue(BigDecimal.valueOf(0)); // 示例：展览收入为 0
        monitoringData.setEventCount(eventCount);
        monitoringData.setComments("自动生成的监控数据");

        // 保存监控数据
        operationalMonitoringService.addMonitoringData(monitoringData);
    }
}
